#include "XnccClient.h"
#include "DatagramClient.h"
#include "EventLoop.h"
#include "InnerType.h"
#include "StreamClient.h"
#include "XnccAddress.h"

namespace xncc {
namespace foundation {

    XnccClient*
    XnccClient::CreateXnccClient(EventLoop* loop, std::shared_ptr<XnccAddress> addr, const std::string& /*nameArg*/)
    {
        if (addr->Type() == shared::XNCC_ADDR_TYPE::IPV4_TCP || addr->Type() == shared::XNCC_ADDR_TYPE::IPV6_TCP ||
            addr->Type() == shared::XNCC_ADDR_TYPE::UNIX_DOMAIN) {
            return new StreamClient(loop, addr);
        }
        if (addr->Type() == shared::XNCC_ADDR_TYPE::IPV4_UDP || addr->Type() == shared::XNCC_ADDR_TYPE::IPV6_UDP) {
            return new DatagramClient(loop, addr);
        }
        if (addr->Type() == shared::XNCC_ADDR_TYPE::SHM) {
            return nullptr;
        }
        return nullptr;
    }

    void XnccClient::Destory(XnccClient* client) { delete client; }

    void XnccClient::enableRetry(int ms)
    {
        retry_        = true;
        retryDelayMs_ = ms;
    }
}  // namespace foundation
}  // namespace xncc